﻿<UserControl x:Class="ReportingManagement.Components.Queries.CustomReports"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
             xmlns:local="clr-namespace:GenericTools.CustomReporting;assembly=GenericTools"
             mc:Ignorable="d" 
             d:DesignHeight="400" d:DesignWidth="662">
    <UserControl.Resources>
        <ObjectDataProvider x:Key="categoriesProvider" ObjectType="{x:Type local:ReportQuerying}" 
                            MethodName="GetAllReportQueryCategories" IsAsynchronous="True" />
    </UserControl.Resources>
    
    <Grid>
        <Grid.ColumnDefinitions>
            <ColumnDefinition MinWidth="150" Width="2*" MaxWidth="600"/>
            <ColumnDefinition Width="Auto" />
            <ColumnDefinition Width="5*" />
        </Grid.ColumnDefinitions>

        <DockPanel Grid.Row="0" Margin="3" Background="LightBlue">
            <DockPanel DockPanel.Dock="Top" LastChildFill="False">
                <Label Content="Report Category" DockPanel.Dock="Left" />
                <Button x:Name="btnRefreshCategories" DockPanel.Dock="Right" Content="Refresh" Width="Auto" Margin="3" 
                        Padding="3" Click="btnRefreshCategories_Click" FontSize="9" />
            </DockPanel>         
            <ListBox x:Name="lstReportCategories" Margin="3" MinHeight="250" Grid.Row="1" DockPanel.Dock="Bottom" 
                     ItemsSource="{Binding Source={StaticResource categoriesProvider}}"
                     ScrollViewer.HorizontalScrollBarVisibility="Disabled">
                <ListBox.ItemTemplate>
                    <DataTemplate>
                        <TextBlock Text="{Binding Name}" TextTrimming="CharacterEllipsis" ToolTip="{Binding Description}" />
                    </DataTemplate>
                </ListBox.ItemTemplate>
            </ListBox>
        </DockPanel>
        <GridSplitter Grid.Column="1" Width="3" VerticalAlignment="Stretch" HorizontalAlignment="Center" Background="LightGray" />

        <Grid Grid.Column="2" Margin="3">
            <Grid.RowDefinitions>
                <RowDefinition Height="Auto"/>
                <RowDefinition Height="Auto"/>
                <RowDefinition Height="Auto"/>
                <RowDefinition/>
                <RowDefinition Height="Auto"/>
            </Grid.RowDefinitions>

            <DockPanel Margin="3">
                <Label Content="Report Name" />
                <ComboBox x:Name="cboReport" DisplayMemberPath="Name" VerticalContentAlignment="Center"
                          ItemsSource="{Binding SelectedItem.Queries, ElementName=lstReportCategories}" />
            </DockPanel>
            <TextBlock Margin="3" Grid.Row="1" Padding="5,0,0,5" TextWrapping="Wrap" Text="{Binding SelectedItem.Description, ElementName=cboReport}" FontStyle="Italic" />
            <StackPanel Orientation="Horizontal" Grid.Row="2">
                <Button x:Name="btnRun" Content="Run" Margin="3" Padding="15,3" Click="btnRun_Click"/>
                <Button x:Name="btnExportToExcel" Content="Export to Excel" Margin="3" Padding="15,3" IsEnabled="False" Click="btnExportToExcel_Click" />
                <Button x:Name="btnTransformToChart" Content="Transform to Chart" Margin="3" Padding="15,3" IsEnabled="False" />
            </StackPanel>

            <DataGrid x:Name="dataGridResults" Grid.Row="3" Margin="3" CanUserAddRows="False" CanUserDeleteRows="False" 
                      IsReadOnly="True" AlternationCount="2" AlternatingRowBackground="WhiteSmoke" />

            <Grid x:Name="dataGridQueryStatus" Grid.Row="4" Margin="3,3,3,0">
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="Auto"/>
                    <ColumnDefinition Width="*"/>
                    <ColumnDefinition Width="Auto" />
                    <ColumnDefinition Width="Auto"/>
                </Grid.ColumnDefinitions>
                
                <TextBlock Text="{Binding ExecutionStatus}" Foreground="{Binding TextColor, Mode=TwoWay}" TextTrimming="CharacterEllipsis" />
                <TextBlock Text="{Binding TimeTaken}" Grid.Column="2" TextTrimming="CharacterEllipsis" Margin="0,0,10,0" />
                <TextBlock Text="{Binding RowsReturned}" Grid.Column="3" TextTrimming="CharacterEllipsis" />                
            </Grid>
        </Grid>
    </Grid>
</UserControl>
